package com.tidc.seaserverservice.service.impl;

import com.tidc.seaservermapper.dao.CommitmentDao;
import com.tidc.seaservermodel.entity.Commitment;
import com.tidc.seaservermodel.entity.Fres;
import com.tidc.seaservermodel.exception.TidcBadParent;
import com.tidc.seaservermodel.util.SpringUtil;
import com.tidc.seaserverservice.service.SecondaryCommitmentService;
import com.tidc.seaserverservice.service.SupervisorCommitmentService;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author ：冯涛滔
 * @date ：Created in 2020/10/8 15:52
 * @description：
 * @modified By：
 * @version:
 */
@Service
public class SecondaryCommitmentServiceImpl implements SecondaryCommitmentService {
    @Resource
    private CommitmentDao commitmentDao;
    @Override
    public Fres<Map<Object, Object>> commitmentList(int type, int pageSize, int pageNum, Authentication authentication) throws TidcBadParent {
        int count = commitmentDao.getSecondaryCount(Integer.parseInt(authentication.getName()),type);
        Map<Object, Object> map = SpringUtil.pagingPrepare(pageSize, pageNum, count);
        List<Commitment> secondaryList = commitmentDao.getSecondaryList(Integer.parseInt(authentication.getName()), type, (pageNum - 1) * pageSize, pageSize);
        map.put("list",secondaryList);
        return Fres.Success(map,"成功");
    }
}
